local skel = fk.CreateSkill {
  name = "emo__huzhao",
}

Fk:loadTranslationTable{
  ["emo__huzhao"] = "互照",
  [":emo__huzhao"] = "出牌阶段开始时，你可以摸四张牌再弃置四张牌，若你弃置了偶数张红色牌，你可以令一名其他角色摸四张牌，若如此做，其下个出牌阶段开始时须弃置四张牌。",

  ["#emo__huzhao-choose"] = "互照：可令一名其他角色摸四张牌，其出牌阶段开始时弃置四张牌",
  ["#emo__huzhao-discard"] = "互照：弃置四张牌，若弃置偶数张红色牌，则可令一名其他角色摸四张牌并于其下个出牌阶段弃四张牌",
  ["@@emo__huzhao"] = "互照",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(4, skel.name)
    local cards = room:askToDiscard(player, {
      min_num = 4, max_num = 4, include_equip = true, skill_name = skel.name, cancelable = false,
      prompt = "#emo__huzhao-discard",
    })
    if #table.filter(cards, function (id) return Fk:getCardById(id).color == Card.Red end) % 2 == 0 and not player.dead then
      local tos = room:askToChoosePlayers(player, {
        min_num = 1, max_num = 1, targets = room:getOtherPlayers(player, false), skill_name = skel.name,
        prompt = "#emo__huzhao-choose",
      })
      if #tos > 0 then
        local to = tos[1]
        room:addTableMark(to, "@@emo__huzhao", player.id)
        to:drawCards(4, skel.name)
      end
    end
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player == target and player.phase == Player.Play and player:getMark("@@emo__huzhao") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getMark("@@emo__huzhao")
    room:setPlayerMark(player, "@@emo__huzhao", 0)
    for _, fromId in ipairs(mark) do
      if player.dead or player:isNude() then break end
      local from = room:getPlayerById(fromId)
      if from and not from.dead then
        room:notifySkillInvoked(from, skel.name, "support", {player.id})
        room:doIndicate(fromId, {player.id})
      end
      room:askToDiscard(player, {  min_num = 4, max_num = 4, include_equip = true, skill_name = skel.name, cancelable = false })
    end
  end,
})

return skel
